//
//  UIView+Ex+Tap.swift
//  APP
//
//  Created by Rdxer on 2017/12/19.
//  Copyright © 2017年 Rdxer. All rights reserved.
//

import Foundation
import FastComponent

private var XXUIView_Tap_GR_KEY: Void?
//private var XXUIView_Tap_View_node_KEY: Void?

public extension XXExtension where Base:UIView{
    fileprivate var tap_GR:UITapGestureRecognizer? {
        get {
            if let tap = objc_getAssociatedObject(base, &XXUIView_Tap_GR_KEY) as? UITapGestureRecognizer{
                return tap
            }
            let tap = UITapGestureRecognizer.init(target: self, action: #selector(UIView.xx_tapGesture(_:)))
            self.tap_GR = tap
            return tap
        }
        set {
            objc_setAssociatedObject(base, &XXUIView_Tap_GR_KEY, newValue, .OBJC_ASSOCIATION_RETAIN)
        }
    }

//    var tap_end_edit_ViewList:WeakNodeList<UIView>? {
//        get {
//            return objc_getAssociatedObject(base, &XXUIView_Tap_View_node_KEY) as? WeakNodeList<UIView>
//        }
//        set {
//            objc_setAssociatedObject(base, &XXUIView_Tap_View_node_KEY, newValue, .OBJC_ASSOCIATION_RETAIN)
//        }
//    }

}
extension UIView:UIGestureRecognizerDelegate{

    func prepareTapGR_end_edit(_ view:UIView?){
        if let tap = xx.tap_GR {

            tap.numberOfTapsRequired = 1
            tap.numberOfTouchesRequired = 1
            tap.delegate = self
            addGestureRecognizer(tap)

        }
    }

    @objc func xx_tapGesture(_ tap:UITapGestureRecognizer){
    }
    public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
        self.endEditing(true)
        return false
    }
}


